import Vue from 'vue'
import Router from 'vue-router'

// 异步加载页面组件
const importPage = view => () =>
    import( /* webpackChunkName: "p-[request]" */ `../components/${view}.vue`)

Vue.use(Router)

const routes = [{
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        name: 'home',
        component: importPage('Home'),
        meta: {
            title: '首页',
            closable: false
        }
    },
    {
        path: '/demo',
        name: 'demo',
        component: importPage('Demo'),
        meta: {
            title: '项目组件'
        },
        children: [{
                path: 'bzt',
                name: 'bzt',
                component: importPage('BZT'),
                meta: {
                    title: '饼状图组件'
                }
            },
            {
                path: 'dtpxzzt',
                name: 'dtpxzzt',
                component: importPage('DTPXZZT'),
                meta: {
                    title: '动态排序柱状图组件'
                }
            }, {
                path: 'jbddmjt',
                name: 'jbddmjt',
                component: importPage('JBDDMJT'),
                meta: {
                    title: '渐变堆叠面积图组件'
                }
            }, {
                path: 'ndgemgt',
                name: 'ndgemgt',
                component: importPage('NDGEMGT'),
                meta: {
                    title: '南丁格尔玫瑰图组件'
                }
            }, {
                path: 'qthxt',
                name: 'qthxt',
                component: importPage('QTHXT'),
                meta: {
                    title: '嵌套环形图组件'
                }
            }, {
                path: 'sdt',
                name: 'sdt',
                component: importPage('SDT'),
                meta: {
                    title: '散点图组件'
                }
            }, {
                path: 'xnfxt',
                name: 'xnfxt',
                component: importPage('XNFXT'),
                meta: {
                    title: '性能分析图组件'
                }
            }, {
                path: 'zftxt',
                name: 'zftxt',
                component: importPage('ZFTXT'),
                meta: {
                    title: '正负条形图组件'
                }
            }, {
                path: 'zxt',
                name: 'zxt',
                component: importPage('ZXT'),
                meta: {
                    title: '折线图组件'
                }
            }, {
                path: 'zzhht',
                name: 'zzhht',
                component: importPage('ZZHHT'),
                meta: {
                    title: '折柱混合图组件'
                }
            }, {
                path: 'zzt', // 默认页和父级路由一致
                name: 'zzt',
                component: importPage('ZZT'),
                meta: {
                    title: '柱状图组件' // 页签标题
                }
            },
        ]
    },
    {
        path: '/notice',
        name: 'notice',
        component: importPage('Notice'),
        meta: {
            title: '公告页面'
        }
    },
    {
        path: '/404',
        name: '404',
        component: importPage('404'),
        meta: {
            title: '找不到页面',
            icon: 'icon-page'
        }
    }
]
// 解决重复路由报错问题
const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(error => error);
};

export default new Router({
    routes
})